/*
 * @Author: szx
 * @Date: 2021-12-11 13:27:33
 * @LastEditTime: 2021-12-11 13:34:46
 * @Description:
 * @FilePath: \leetcode\200-299\225\225.js
 */
var MyStack = function () {
    this.queue = [];
};

/**
 * @param {number} x
 * @return {void}
 */
MyStack.prototype.push = function (x) {
    this.queue.push(x);
};

/**
 * @return {number}
 */
MyStack.prototype.pop = function () {
    let length = this.queue.length;
    while (length >= 1) {
        length--;
        this.queue.push(this.queue.pop());
    }
    return this.queue.pop();
};

/**
 * @return {number}
 */
MyStack.prototype.top = function () {
    let length = this.queue.length;
    while (length >= 1) {
        length--;
        this.queue.push(this.queue.pop());
    }
    const res = this.queue.pop();
    this.queue.push(res);
    return res;
};

/**
 * @return {boolean}
 */
MyStack.prototype.empty = function () {
    return this.queue.length == 0;
};

/**
 * Your MyStack object will be instantiated and called as such:
 * var obj = new MyStack()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.empty()
 */
